import { Component } from '@angular/core';

import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {GetVideoDetailService} from "../../service/http-service/getVideoDetail.service";
import {ApplicantService} from "../../service/http-service/applicant.service";


// import {HomePage} from "../home/home";
// import {PhonePage} from "../phone/phone";


/**
 * Generated class for the MePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

 @IonicPage()
@Component({
  selector: 'page-me',
  templateUrl: 'me.html',
})

export class MePage {
  phone: string;
  // expiredTime: string;
  // memType: string;
  usrName: string;
  imgUrl: string;
  usrInfo = [];
  video: any;
  time1: any;
  usrVip: string;
  phoneNum: any;
  phoneNum1: any;
  phoneNum2: any;
  memberInfo: string;


  constructor(public navCtrl: NavController, public navParams: NavParams,
              public getVideoDetailService:GetVideoDetailService,
              public applicantService:ApplicantService) {
  }

  // ionViewDidLoad() {
  //   console.log('ionViewDidLoad MePage');
  // }

  ionViewWillEnter(){
    console.log('ionViewWillEnter');
    var usrInfo= localStorage.getItem("options");
    //this.phone = JSON.parse(usrInfo).phone;
   this.usrName = JSON.parse(usrInfo).username;
    this.imgUrl = JSON.parse(usrInfo).header_img;
    this.phoneNum = JSON.parse(usrInfo).phone.toString();
    // console.log(this.phoneNum);
    if(this.phoneNum!=null||this.phoneNum!=undefined){
      this.phoneNum1=this.phoneNum.substr(0,3);
      this.phoneNum2=this.phoneNum.substr(8,3);
    }

    //this.memType = JSON.parse(usrInfo).header_img;
    this.getMyVipDetail();

    }


  // private newMethod() {
  //   return this.usrInfo;
  // }

  // private newMethod() {
  //   return this.usrInfo;
  // }

  open_home() {

   // this.navCtrl.remove(this.navCtrl.last().index, 1);
    this.navCtrl.push('HomePage');
  };

  openPhone (){

    this.navCtrl.push('PhonePage',);
  }

  openPurchasehistory (){

    this.navCtrl.push('PurchaseHistoryPage',);
  }

  openVip (){

    this.navCtrl.push('VipPage',);
  }

  openHistory (){

    this.navCtrl.push('HistoryPage',);
  }

//格式化评论日期
  date1(time: any) {
    return new Date(time).toLocaleString().replace(/:\d{1,2}$/, ' ');
  }

  date2(time: any){
    if (time != null){
      var date = new Date(time);
      return date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + date.getDate()+ '日';
    }
  }


  getMyVipDetail() {
    this.getVideoDetailService.getMyVip().subscribe(resp => {
      if (resp.data !== null && resp.code == 200) {
        this.video = resp.data;
        this.time1 = resp.data.expiration_time;
        this.usrVip="1";
        this.memberInfo="VIP会员";

        // console.log(resp.data);
        // localStorage.setItem("video111", resp.data);
        // console.log(this.video.url)


      }else if (resp.data==null&&resp.code == 400){
        console.log("ghjkhljllll");
        this.usrVip="2";

        this.memberInfo="普通会员";
        console.log(this.usrVip);
        console.log(typeof(this.usrVip));
      }
      else if (resp.data !== null && resp.code == 1401) {
        console.log("errrovideo");
        this.applicantService.freshTokenn();
      }
    }, error2 => {

      console.log(error2);
    });


  }



}
